﻿using NPOI.XSSF.Streaming.Values;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using XingLucifer.IBase.Enums;

namespace UIWindows.Tools.Converter
{
    public class StringToBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //if (value is string stringValue && parameter is string stringParameter)
            //{
            //    return stringValue == stringParameter;
            //}

            //return false;
            TaskTypes typeValue;
            TaskTypes typeParameter;
            
            if (TaskTypes.TryParse(value.ToString(), out typeValue)  && TaskTypes.IsDefined(typeof(TaskTypes), int.Parse(parameter.ToString())))
            {
                return typeValue == (TaskTypes)int.Parse(parameter.ToString());
            }

            return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool boolValue && boolValue)
            {
                return (TaskTypes)int.Parse(parameter.ToString());
            }

            return null;
        }
    }
}
